package com.hxkcloud.nurse.alarm;

import android.content.Context;
import android.os.PowerManager;

/**
 * Created by william_sun on 2016-08-18.
 * Description:Hold a wakelock that can be acquired in the AlarmReceiver and
 * released in the AlarmAlert activity
 * http://blog.csdn.net/eyu8874521/article/details/7912199
 */
public class AlarmAlertWakeLock {
    //保持屏幕常亮
    private static PowerManager.WakeLock sCpuWakeLock;

    static void acquireCpuWakeLock(Context context) {
        if (sCpuWakeLock != null) {
            return;
        }

        PowerManager pm =
                (PowerManager) context.getSystemService(Context.POWER_SERVICE);

        sCpuWakeLock = pm.newWakeLock(
                PowerManager.PARTIAL_WAKE_LOCK |
                        PowerManager.ACQUIRE_CAUSES_WAKEUP |
                        PowerManager.ON_AFTER_RELEASE, "AlarmClock");
        sCpuWakeLock.acquire();
    }

    static void releaseCpuLock() {
        if (sCpuWakeLock != null) {
            sCpuWakeLock.release();
            sCpuWakeLock = null;
        }
    }
}
